<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="简介用于构建用户界面的 JavaScript 库, 它是FaceBook的一个开源项目 它的设计模式为Javascript MV* 框架 (MVC&#x2F;MVVM&#x2F;MVP&#x2F;MV), 无论是哪种MV*系列，都涉及到了Model和View，如果单纯的只有Model和View，他们是没有办法一起协同工作的，所以就有了各种MV..的设计模式 它是 针对UI层的Web-webApp应用方案 优点 组件化开发+模块">
<meta name="keywords" content="君须知，未见之处，犹多宝藏">
<meta property="og:type" content="article">
<meta property="og:title" content="React">
<meta property="og:url" content="http:&#x2F;&#x2F;yoursite.com&#x2F;2019&#x2F;11&#x2F;16&#x2F;React&#x2F;index.html">
<meta property="og:site_name" content="White 的个人博客">
<meta property="og:description" content="简介用于构建用户界面的 JavaScript 库, 它是FaceBook的一个开源项目 它的设计模式为Javascript MV* 框架 (MVC&#x2F;MVVM&#x2F;MVP&#x2F;MV), 无论是哪种MV*系列，都涉及到了Model和View，如果单纯的只有Model和View，他们是没有办法一起协同工作的，所以就有了各种MV..的设计模式 它是 针对UI层的Web-webApp应用方案 优点 组件化开发+模块">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-11-17T08:24:05.757Z">
<meta name="twitter:card" content="summary">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/11/16/React/"/>





  <title>React | White 的个人博客</title>
  








</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
<a href="https://github.com/whitechiina" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#f55555; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">White 的个人博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">君须知，未见之处，犹多宝藏</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/16/React/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="White">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="White 的个人博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">React</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-16T00:12:14+08:00">
                2019-11-16
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/React/" itemprop="url" rel="index">
                    <span itemprop="name">React</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.9k字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  7分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h3><p>用于构建用户界面的 JavaScript 库, 它是FaceBook的一个开源项目</p>
<p>它的设计模式为Javascript MV* 框架 (MVC/MVVM/MVP/MV<em>), 无论是哪种MV*</em>系列，都涉及到了Model和View，如果单纯的只有Model和View，他们是没有办法一起协同工作的，所以就有了各种MV..的设计模式</p>
<p>它是 针对UI层的Web-webApp应用方案</p>
<h3 id="优点"><a href="#优点" class="headerlink" title="优点"></a>优点</h3><ol>
<li>组件化开发+模块化开发</li>
<li>高效的虚拟DOM</li>
<li>前后端通吃的WebApp框架  (Vue前端框架, Nuxtjs)</li>
<li>跨平台运行(React-native) (甚至可以产出iOS的android的应用)  (Flutter)</li>
<li>庞大的React生态系统 (比vuejs的插件多的多)(它是一个国外的项目)  (而且北京3年以上react的多一些)</li>
</ol>
<h3 id="缺点"><a href="#缺点" class="headerlink" title="缺点"></a>缺点</h3><ol>
<li>相比Vuejs, 学习曲线陡峭</li>
<li>需要一定的前端开发经验(小程序/vuejs/angularjs/js基础更好)</li>
<li>设计思想与方式有所不同</li>
</ol>
<h3 id="全家桶"><a href="#全家桶" class="headerlink" title="全家桶"></a>全家桶</h3><ol>
<li>react基础语法</li>
<li>webpack+nodejs基础</li>
<li>react-router (React里的路由) (react-router-dom)</li>
<li>Redux (实际开发用: React-Redux) (相当于Vuex)</li>
<li>create-react-app (React的官方脚手架)</li>
<li>网络请求的框架 — axios, 以及转发代理— (http-proxy-middleware)</li>
</ol>
<h3 id="学完能干啥"><a href="#学完能干啥" class="headerlink" title="学完能干啥"></a>学完能干啥</h3><p>可以成吨的提高开发效率, 开发移动端/PC端/兼容前后台的页面和不同设备的项目</p>
<h3 id="故事"><a href="#故事" class="headerlink" title="故事"></a>故事</h3><p>React 起源于 Facebook 的内部项目, 他从最早的UI引擎变成了一整套前后端通吃的, Web App 解决方案。衍生的 React Native(React语法) 项目, 目标更是宏伟，希望用写 Web App 的方式去写 Native App (iOS(OC)和Android(JAVA+VS)。如果能够实现，整个互联网行业都会被颠覆，因为同一组人只需要写一次 UI ，就能同时运行在服务器、浏览器和手机。</p>
<h2 id="使用步骤"><a href="#使用步骤" class="headerlink" title="使用步骤"></a>使用步骤</h2><h3 id="渲染"><a href="#渲染" class="headerlink" title="渲染"></a>渲染</h3><ol>
<li><p>引入react.js和react-dom.js, 如果使用jsx语法, 需要再引入babel.js</p>
<ul>
<li>react-dom.js 处理跟DOM相关的操作, 暴露对象为ReactDOM</li>
<li>babel.js 是为了将jsx语法, 通过babel编译成ES5的代码运行在浏览器中</li>
</ul>
</li>
<li><p>声明根标签(用于指定虚拟DOM挂载的位置)</p>
</li>
<li><p>在script标签上, 声明JSX语法, type=”text/babel”</p>
<ul>
<li>JSX是一种JavaScript的语法扩展，运用于<a href="https://baike.baidu.com/item/React/18077599" target="_blank" rel="noopener">React</a>架构中，其格式比较像是模版语言，但事实上完全是在<a href="https://baike.baidu.com/item/JavaScript/321142" target="_blank" rel="noopener">JavaScript</a>内部实现的。元素是构成React应用的最小单位，JSX就是用来声明React当中的元素，React使用JSX来描述用户界面。</li>
</ul>
</li>
<li><p>ReactDOM.render(), 把虚拟DOM挂载到哪个标签身上, 给用户查看</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&lt;script src=<span class="string">"./build/react-0.14.0.js"</span>&gt;<span class="xml"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br><span class="line">&lt;script src=<span class="string">"./build/react-dom-0.14.0.js"</span>&gt;<span class="xml"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br><span class="line">&lt;script src=<span class="string">"./build/browser.min.js"</span>&gt;<span class="xml"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br><span class="line">&lt;div id=<span class="string">"app"</span>&gt;<span class="xml"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line">&lt;script type=<span class="string">"text/babel"</span>&gt;</span><br><span class="line">ReactDOM.render(</span><br><span class="line">	&lt;h1&gt;Hello World!<span class="xml"><span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span>,</span><br><span class="line">	<span class="built_in">document</span>.getElementById(<span class="string">'app'</span>)</span><br><span class="line">) <span class="comment">// render()方法用于渲染页面, 参数1: React根标签, 参数2: 目标位置</span></span><br><span class="line">&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure>

</li>
</ol>
<blockquote>
<p>注意: 在浏览器中是无法识别react中的jsx语法糖，采用babel实现jsx语法转化es5语法</p>
</blockquote>
<h3 id="变量使用"><a href="#变量使用" class="headerlink" title="变量使用"></a>变量使用</h3><ol>
<li><p>HTML 中使用 JS, 用大括号</p>
</li>
<li><p>在render内, 只能有一个根标签</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> userName = <span class="string">"react"</span>;</span><br><span class="line">ReactDOM.render(</span><br><span class="line">        &lt;div&gt;</span><br><span class="line">            &lt;h1&gt;以天为被&lt;<span class="regexp">/h1&gt;</span></span><br><span class="line"><span class="regexp">            &lt;h3&gt;&#123;username&#125;&lt;/</span>h3&gt;</span><br><span class="line">            &lt;h1&gt;以地为床&lt;<span class="regexp">/h1&gt;</span></span><br><span class="line"><span class="regexp">        &lt;/</span>div&gt;,</span><br><span class="line">        <span class="built_in">document</span>.getElementById(<span class="string">"app"</span>)</span><br><span class="line">    )</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h3 id="数组使用"><a href="#数组使用" class="headerlink" title="数组使用"></a>数组使用</h3><ol>
<li>需要给每个循环的标签, 添加key属性, 而且值是唯一的</li>
<li>在JSX的HTML当中, 直接返回夹着数据的标签即可</li>
</ol>
<h3 id="属性使用"><a href="#属性使用" class="headerlink" title="属性使用"></a>属性使用</h3><ol>
<li>原生的class -&gt; className 代替</li>
<li>原生的for属性 -&gt;  htmlFor 代替</li>
<li>单标签, 最后一定要加上 /</li>
<li>属性都采用 驼峰 标识 (比如原生事件onclick, 就要写成onClick)</li>
</ol>
<blockquote>
<p>JSX语法一定要严格, 因为它比较死板</p>
</blockquote>
<blockquote>
<p>动态class: className={obj[‘later’] ? ‘success’ : ‘error’}</p>
</blockquote>
<h3 id="方法使用"><a href="#方法使用" class="headerlink" title="方法使用"></a>方法使用</h3><ol>
<li>在JS中ReactDOM.render()之外定义方法</li>
<li>在JSX语法标签模板中, {方法名()} 使用即可</li>
<li>方法里可以返回标签/返回标签数组/用于事件的方法上</li>
</ol>
<blockquote>
<p>事件都要使用驼峰标识, 跟原生onclick有些差别</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;button onClick=&#123;fnThree&#125;&gt;点我点我&lt;<span class="regexp">/button&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="标签创建"><a href="#标签创建" class="headerlink" title="标签创建"></a>标签创建</h2><p>这里只是创建一个标签对象, 不是组件</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">React.createElement() 方法</span><br><span class="line"><span class="comment">// 参数1: 标签名</span></span><br><span class="line">    <span class="comment">// 参数2: 标签属性 (是个对象)</span></span><br><span class="line">    <span class="comment">// 参数3: 此标签的内容 (可以理解为innerHTML)</span></span><br><span class="line">    <span class="keyword">let</span> titleCom = React.createElement(</span><br><span class="line">        <span class="string">"p"</span>,</span><br><span class="line">        &#123;<span class="string">"className"</span>: <span class="string">'title_p'</span>&#125;,</span><br><span class="line">        <span class="string">"Hello, React"</span></span><br><span class="line">    );</span><br></pre></td></tr></table></figure>

<h2 id="组件创建"><a href="#组件创建" class="headerlink" title="组件创建"></a>组件创建</h2><ol>
<li><p>React.createClass({})</p>
</li>
<li><p>构造函数function 组件名(){}</p>
</li>
<li><p>class 组件名 extends React.Component  (组件名要大写)</p>
</li>
<li><p>如果向组件内传值</p>
<ul>
<li><p>组件内直接使用 this.props.变量名</p>
</li>
<li><p>使用组件的地方, 直接用变量名=传值 </p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">组件内使用:</span><br><span class="line">&lt;p&gt;子组件接收到的值是:  --- &#123;<span class="keyword">this</span>.props.myTitle&#125;&lt;<span class="regexp">/p&gt;</span></span><br><span class="line"><span class="regexp">传值</span></span><br><span class="line"><span class="regexp">&lt;MyTr myTitle=&#123;'你好啊'&#125; /</span>&gt;</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>组件嵌套使用: 其实就是在组件内直接使用 另外一个组件</p>
</li>
</ol>
<h2 id="动态style"><a href="#动态style" class="headerlink" title="动态style"></a>动态style</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;p style=&#123;&#123;color: &apos;red&apos;&#125;&#125;&gt;我是动态的style&lt;/p&gt;</span><br><span class="line">&lt;p style=&#123;&#123;color: &quot;yellow&quot;, backgroundColor: &quot;blue&quot;&#125;&#125;&gt;如果多对用逗号隔开&lt;/p&gt;</span><br><span class="line"></span><br><span class="line">// 最外层的大括号: 代表这里是JS的代码</span><br><span class="line">// 内层的大括号: 代表这是CSS样式的对象</span><br></pre></td></tr></table></figure>

<h2 id="资料"><a href="#资料" class="headerlink" title="资料"></a>资料</h2><h3 id="JSX语法"><a href="#JSX语法" class="headerlink" title="JSX语法"></a>JSX语法</h3><ol>
<li>JS中 使用标签, 直接使用&lt;&gt; 声明标签</li>
<li>如果在JS的html标签中, 要写JS代码, 需要使用 {} 扩起来</li>
<li>大括号内, 可以使用变量/表达式/三目运算/数组 (但是不能直接写入一个对象{name: ‘人名’})</li>
<li>如果返回一堆标签, 可以用数组装着, 然后在{} 直接使用数组变量即可</li>
<li>在map循环时候, 返回一个个标签, 组成一个数组, 然后使用</li>
<li>在JSX中, class和for是关键字, 所以<ul>
<li>class -&gt; className</li>
<li>for -&gt; htmlFor (label标签)</li>
<li>都要使用驼峰标识</li>
</ul>
</li>
</ol>
<h3 id="速查表"><a href="#速查表" class="headerlink" title="速查表"></a>速查表</h3><table>
<thead>
<tr>
<th>方法/属性名</th>
<th>解析</th>
<th>备注</th>
</tr>
</thead>
<tbody><tr>
<td>ReactDOM.render()</td>
<td>把虚拟DOM渲染到指定的真实标签中</td>
<td>2个参数, 参数1只能有一个根标签</td>
</tr>
<tr>
<td>React.createElement()</td>
<td>创建一个在内存中的虚拟DOM标签</td>
<td>3个参数, <br />参数1: 标签名, <br />参数2: 属性和值(最好是一个对象格式) <br />参数3: 此标签的内容….(可以是标签/字符串/多个)</td>
</tr>
<tr>
<td>React.createClass()</td>
<td>创建一个组件(类似于自定义标签)</td>
<td>注意1: 组件名一定要大写字母开头 注意2: 参数是一个对象 注意3: 在render函数中return 一个根标签(是组件要被渲染的标签)</td>
</tr>
<tr>
<td>构造函数创建组件</td>
<td></td>
<td>注意1: 没有render, 直接return 一个根标签就可以了</td>
</tr>
<tr>
<td>class xxx extends React.Component {}</td>
<td>常用在创建React组件的地方</td>
<td>注意1: 要使用render() 来返回根标签 注意2: 在父-&gt;子传值时, 直接定义变量名, 使用时this.props.变量名即可 直接使用</td>
</tr>
</tbody></table>
<h3 id="面试题"><a href="#面试题" class="headerlink" title="面试题"></a>面试题</h3><ol>
<li>react中类组件和函数组件不同?</li>
</ol>
<p>import { React } from ‘react’<br>var App = (){<br>return()<br>}<br>类组件：<br>import { React,Component } from ‘react’<br>class App extends Component{<br>render(){<br>return()<br>}<br>}<br>函数组件无state和生命周期，传值需要用props<br>类组件有state和生命周期，传值需要this.props </p>
<ol start="2">
<li><p>JSX是什么? 浏览器怎么解析JSX</p>
<p>JSX 将 HTML 语法直接加入到 JavaScript 代码中，再通过翻译器转换到纯 JavaScript 后由浏览器执行。在实际开发中，JSX 在产品打包阶段都已经编译成纯 JavaScript，不会带来任何副作用，反而会让代码更加直观并易于维护。<br>浏览器中通过给script标签添加type=”text/bable”属性来解析jsx</p>
</li>
</ol>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/11/15/%E5%88%9D%E8%AF%86Vue/" rel="next" title="初识Vue">
                <i class="fa fa-chevron-left"></i> 初识Vue
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/11/17/WEB%E5%89%8D%E7%AB%AF%E7%9F%A5%E8%AF%86%E4%BD%93%E7%B3%BB%E7%B2%BE%E7%AE%80/" rel="prev" title="WEB前端知识体系精简">
                WEB前端知识体系精简 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/1.jpg"
                alt="White" />
            
              <p class="site-author-name" itemprop="name">White</p>
              <p class="site-description motion-element" itemprop="description">君须知，未见之处，犹多宝藏</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/%7C%7Carchive">
              
                  <span class="site-state-item-count">10</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/yourname" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#简介"><span class="nav-number">1.</span> <span class="nav-text">简介</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#优点"><span class="nav-number">2.</span> <span class="nav-text">优点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#缺点"><span class="nav-number">3.</span> <span class="nav-text">缺点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#全家桶"><span class="nav-number">4.</span> <span class="nav-text">全家桶</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#学完能干啥"><span class="nav-number">5.</span> <span class="nav-text">学完能干啥</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#故事"><span class="nav-number">6.</span> <span class="nav-text">故事</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用步骤"><span class="nav-number"></span> <span class="nav-text">使用步骤</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#渲染"><span class="nav-number">1.</span> <span class="nav-text">渲染</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#变量使用"><span class="nav-number">2.</span> <span class="nav-text">变量使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数组使用"><span class="nav-number">3.</span> <span class="nav-text">数组使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#属性使用"><span class="nav-number">4.</span> <span class="nav-text">属性使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#方法使用"><span class="nav-number">5.</span> <span class="nav-text">方法使用</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#标签创建"><span class="nav-number"></span> <span class="nav-text">标签创建</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#组件创建"><span class="nav-number"></span> <span class="nav-text">组件创建</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#动态style"><span class="nav-number"></span> <span class="nav-text">动态style</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#资料"><span class="nav-number"></span> <span class="nav-text">资料</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#JSX语法"><span class="nav-number">1.</span> <span class="nav-text">JSX语法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#速查表"><span class="nav-number">2.</span> <span class="nav-text">速查表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#面试题"><span class="nav-number">3.</span> <span class="nav-text">面试题</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">White</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-heart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">26.9k</span>
  
</div>



<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共26.9k 字</span>
</div>

        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","hOffset":100,"width":150,"height":300},"mobile":{"show":true},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
